<template>
	<view class="parent-view">
		<swiper :current="tabIndex" class="swiper-box" @change="ontabchange">
			<swiper-item class="swiper-item" v-for="(tab,spIndex) in tabBars" :key="spIndex">
				<scroll-view class="swiper-sv" :scroll-y="true" lower-threshold="30" @scrolltolower="loadMoreList">
					<!-- 我的邀请 -->
					<view class="yq-view" v-if="tab.name=='我的邀请'">
						<!-- 点击绑定推荐人 -->
						<view v-if="userData.vip=='0'&&!userData.inviter_name" class="yq-binding-view" @click="bindingRecommend">
							<text class="yq-binding-desc">点击绑定推荐人</text>
							<image class="yq-binding-img" src="../../static/icon-binding-arrow.png"></image>
						</view>
						<view style="flex-direction: column;display: flex;box-sizing: border-box;width: 100%;" v-for="(yaoqingItem,yaoqingIndex) in yaoqingList">
							<view class="yq-list">
								<image class="yq-list-img" :src="yaoqingItem.avatar"></image>
								<view class="yq-list-desc-view">
									<view class="yq-desc-view" style="margin-top: 5rpx;">
										<text class="yq-desc-name">{{yaoqingItem.name}}</text>
										<text class="yq-desc-time-txt">开通时间</text>
									</view>
									<view class="yq-desc-view" style="margin-top: 15rpx;">
										<text class="yq-desc-mobile">{{yaoqingItem.mobile}}</text>
										<text class="yq-desc-time">{{yaoqingItem.jointime}}</text>
									</view>
								</view>
							</view>
							<view style="width: 690rpx;background-color: #F5F6FA;height: 2rpx;margin-left: 30rpx;"></view>
						</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
		<LoginTipDialog :isShow="isShowLoginTip" dataSource="登录查看具体信息" @returnLoginTipDialog="returnLoginTipDialog" />
		<inputDialog :isShow="isShowBinding" :dataSource="dialogData" @returnInputDialog="returnInputDialog" />
	</view>
</template>

<script>
	import request from '../index/request.js';
	import inputDialog from "@/components/input-dialog/input-dialog.vue";
	import LoginTipDialog from "@/components/login-tip-dialog/login-tip-dialog.vue";
	export default {
		components: {
			LoginTipDialog,inputDialog
		},
		data() {
			return {
				tabIndex: 0,
				tabBars: [{
						name: '我的邀请',
					}
				],
				isShowBinding:false,
				dialogData:{
					title:"温馨提示",
					hint:"请输入绑定人的手机号",
					leftTxt:"取消",
					rightTxt:"确定",
					tag:"binding"
				},
				yaoqingPage: 1,
				yaoqingList: [],
				shouYiData:{},
				userData:{}
			}
		},
		methods: {
			onShow: function() {
				this.share.shareType = 0
			},
			onLoad: function(options) {
				this.appUtil.saveAppInviteId(options)
				for (var i = 0; i < this.tabBars.length; i++) {
					if(this.tabBars[i].name==options.title){
						this.tabIndex=i
					}
				}
				this.getUserData()
				this.getYaoQingList()
				this.getStatisticsCash()
			},
			getUserData: function() {
				var that = this
				var user = uni.getStorageSync("shiqin-user")
				this.userPQD = user.PQD
				request.post("api/user/index", {}).then(data => {
					that.userData = data;
					uni.setStorageSync("shiqin-user",data)
				})
			},
			bindingRecommend:function(){
				this.isShowBinding=true
			},
			returnInputDialog:function(e){
				this.isShowBinding=e.isclose
				if(e.tag){
					this.inviterBinding(e.inputStr)
				}
			},
			inviterBinding: function(mobile) {
				var that = this
				request.post("api/user/inviter_binding", {
					mobile:mobile
				}).then(data => {
					that.getUserData()
				})
			},
			ontabtap: function(e) {
				let index = e.target.dataset.current || e.currentTarget.dataset.current;
				this.tabIndex = index;
			},
			ontabchange: function(e) {
				let index = e.target.current || e.detail.current;
				this.tabIndex = index;
			},
			loadMoreList: function(e) {
				switch (this.tabBars[this.tabIndex].name) {
					case '我的邀请':
						this.yaoqingPage++
						this.getYaoQingList()
						break
				}
			},
			getYaoQingList: function() {
				var that = this
				request.post("api/user/invite_list", {
					page: that.yaoqingPage,
					type: 3
				}).then(data => {
					if (that.yaoqingPage == 1) {
						that.yaoqingList = data
					} else {
						for (var i = 0; i < data.length; i++) {
							that.yaoqingList.push(data[i])
						}
					}
				})
			},
			getStatisticsCash: function() {
				var that = this
				request.post("api/user/statistics_cash", {
				}).then(data => {
					this.shouYiData=data
				})
			},
			goShangDian:function(){
				uni.navigateTo({
					url:"../../shopping-home/index"
				})
			}
		}
	}
</script>

<style>
	@import "index.css";
</style>
